package com.zzh.bc.modules.oss;

import java.util.Enumeration;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @description:
 * @fileName: FileType.java
 * @author: dongv
 * @createAt: 2021/11/26 21:20 上午
 * @updateBy: dongv
 * @remark: dongv
 */
public class FileType {

    public final static ConcurrentHashMap<String, String> FILE_TYPE_MAP = new ConcurrentHashMap<>();
    public final static ConcurrentHashMap<String, String> PREFIX_FILE_TYPE = new ConcurrentHashMap<>();
    /**
     * 文件mimeType，扩展名
     */
    public final static ConcurrentHashMap<String, String> FILE_MIME_EXT_TYPE = new ConcurrentHashMap<>();

    private FileType() {
    }

    static {
        getAllFileType(); // 初始化文件类型信息
    }

    /**
     * getAllFileType,常见文件头信息
     */
    private static void getAllFileType() {
        FILE_TYPE_MAP.put("js", "696b2e71623d696b2e71");
        FILE_TYPE_MAP.put("ps", "252150532D41646F6265");
        FILE_TYPE_MAP.put("gz", "1f8b0800000000000000");
        FILE_TYPE_MAP.put("mf", "4d616e69666573742d56");
        FILE_TYPE_MAP.put("jpg", "ffd8ffe000104a464946");
        FILE_TYPE_MAP.put("jpeg", "ffd8ffe000104a464946");
        FILE_TYPE_MAP.put("png", "89504e470d0a1a0a0000");
        FILE_TYPE_MAP.put("gif", "47494638");
        FILE_TYPE_MAP.put("apk", "504b0304");
        FILE_TYPE_MAP.put("tif", "49492a00227105008037");
        FILE_TYPE_MAP.put("bmp", "424d");
        FILE_TYPE_MAP.put("dwg", "41433130313500000000");
        FILE_TYPE_MAP.put("htm", "3c21646f637479706520");
        FILE_TYPE_MAP.put("css", "48544d4c207b0d0a0942");
        FILE_TYPE_MAP.put("rtf", "7b5c727466315c616e73");
        FILE_TYPE_MAP.put("psd", "38425053000100000000");
        FILE_TYPE_MAP.put("eml", "46726f6d3a203d3f6762");
        FILE_TYPE_MAP.put("doc", "d0cf11e0a1b11ae10000");
        FILE_TYPE_MAP.put("xls", "d0cf11e0a1b11ae10000");
        FILE_TYPE_MAP.put("vsd", "d0cf11e0a1b11ae10000");
        FILE_TYPE_MAP.put("mdb", "5374616E64617264204A");
        FILE_TYPE_MAP.put("pdf", "255044462d312e");
        FILE_TYPE_MAP.put("flv", "464c5601050000000900");
        FILE_TYPE_MAP.put("mp4", "00000020667479706d70");
        FILE_TYPE_MAP.put("mp3", "49443303000000002176");
        FILE_TYPE_MAP.put("mpg", "000001ba210001000180");
        FILE_TYPE_MAP.put("wmv", "3026b2758e66cf11a6d9");
        FILE_TYPE_MAP.put("wav", "52494646e27807005741");
        FILE_TYPE_MAP.put("avi", "52494646d07d60074156");
        FILE_TYPE_MAP.put("mid", "4d546864000000060001");
        FILE_TYPE_MAP.put("zip", "504b0304140000000800");
        FILE_TYPE_MAP.put("rar", "526172211a0700cf9073");
        FILE_TYPE_MAP.put("ini", "235468697320636f6e66");
        FILE_TYPE_MAP.put("jar", "504b03040a0000000000");
        FILE_TYPE_MAP.put("exe", "4d5a9000030000000400");
        FILE_TYPE_MAP.put("jsp", "3c25402070616765206c");
        FILE_TYPE_MAP.put("xml", "3c3f786d6c2076657273");
        FILE_TYPE_MAP.put("sql", "494e5345525420494e54");
        FILE_TYPE_MAP.put("bat", "406563686f206f66660d");
        FILE_TYPE_MAP.put("chm", "49545346030000006000");
        FILE_TYPE_MAP.put("mxp", "04000000010000001300");
        FILE_TYPE_MAP.put("wps", "d0cf11e0a1b11ae10000");
        FILE_TYPE_MAP.put("html", "3c21444f435459504520");
        FILE_TYPE_MAP.put("rmvb", "2e524d46000000120001");
        FILE_TYPE_MAP.put("java", "7061636b616765207765");
        FILE_TYPE_MAP.put("docx", "504b0304140006000800");
        FILE_TYPE_MAP.put("xlsx", "504b0304140006000800");
        FILE_TYPE_MAP.put("class", "cafebabe0000002e0041");
        FILE_TYPE_MAP.put("torrent", "6431303a637265617465");
        FILE_TYPE_MAP.put("properties", "6c6f67346a2e726f6f74");
        FILE_TYPE_MAP.put("dbx", "CFAD12FEC5FD746F");
        FILE_TYPE_MAP.put("mov", "6D6F6F76");
        FILE_TYPE_MAP.put("wpd", "FF575043");
        FILE_TYPE_MAP.put("pst", "2142444E");
        FILE_TYPE_MAP.put("qdf", "AC9EBD8F");
        FILE_TYPE_MAP.put("pwl", "E3828596");
        FILE_TYPE_MAP.put("ram", "2E7261FD");
        FILE_TYPE_MAP.put("jks", "FEEDFEED");
        Enumeration<String> keys = FILE_TYPE_MAP.keys();
        while (keys.hasMoreElements()) {
            String key = keys.nextElement();
            String value = FILE_TYPE_MAP.get(key);
            PREFIX_FILE_TYPE.put(value, key);
        }

        FILE_MIME_EXT_TYPE.put("application/msword", "doc");
        FILE_MIME_EXT_TYPE.put("application/vnd.openxmlformats-officedocument.wordprocessingml.document", "doc");
        FILE_MIME_EXT_TYPE.put("image/jpeg", "jpeg");
        FILE_MIME_EXT_TYPE.put("application/vnd.android.package-archive", "jpeg");
    }


}
